package router

import (
	"github.com/gin-gonic/gin"
	_ "server/docs"
	"server/internal/middleware"
	"server/internal/model"
	"server/internal/router/manager"
	v12 "server/internal/router/v1"
)

func handleRequest(c *gin.Context) {
	c.HTML(200, "index.html", gin.H{}) // index.html为静态HTML页面的文件名
}

func NewRouter() *gin.Engine {
	var R = gin.New()

	//R.StaticFile("/home", "D:\\gowork\\src\\palmer\\server\\documents\in")
	R.Use(gin.Recovery())
	//R.Use(middleware.AccessLog())
	//R.Use(middleware.Tracing())

	R.POST("api/v1/login", v12.Login)
	R.POST("api/v1/logout", v12.Logout)
	//R.GET("/", handleRequest)
	R.GET("/ws", model.WsSsh)

	R.GET("/ws/socketLink", v12.SocketLink)

	v1 := R.Group("api/v1")

	v1.Use(middleware.JWT())

	{
		//用户管理，增删改查
		v1.GET("/user", v12.UserList)
		v1.GET("/user/project_list/:name", v12.UserProject)
		v1.POST("/user", v12.CreateUser)           //创建用户
		v1.PUT("/user", v12.ModifyUser)            //修改用户
		v1.DELETE("/user/:id", v12.DeleteUser)     //删除用户
		v1.DELETE("/user/token/:id", v12.GetToken) //获取用户Token

		//用例管理，增删改查
		v1.GET("/testcase/meau", v12.ListCaseMeau)
		v1.POST("/testcase/meau", v12.CreateCaseMeau)
		v1.PUT("/testcase/meau", v12.UpdateCaseMeau)
		v1.DELETE("/testcase/meau:name", v12.DeleteCaseMeau)

		v1.GET("/testcase", v12.TestCaseList)
		v1.POST("/testcase", v12.CreateTestCase)
		v1.PUT("/testcase/:name", v12.UpdateTestCase)
		v1.DELETE("/testcase/:id", v12.DeleteTestCase)

		//任务管理
		v1.GET("/task", v12.ListTask)
		v1.GET("/task/info/:name", v12.QueryTaskInfo)
		v1.PUT("/task", v12.UpdateTask)
		v1.PUT("/task/switch", v12.TaskSwitch)
		v1.PUT("/task/stop", v12.StopTask)
		v1.PUT("/task/run", v12.RunTask)
		v1.POST("/task", v12.CreateTask)
		v1.POST("/task/copy", v12.CopyTask)
		v1.DELETE("/task/:name", v12.DeleteTask)

		//历史任务
		v1.GET("/histask", v12.ListHisTask)

		//流水线
		v1.GET("/pipeline", v12.ListPipeline)             //获取流水线列表
		v1.GET("/pipeline/info/:name", v12.QueryPipeInfo) //查询流水线信息
		v1.PUT("/pipeline", v12.UpdatePippipe)            // 修改流水线信息
		v1.PUT("/pipeline/switch", v12.PipeSwitch)        //开启或关闭流水线定时任务
		v1.POST("/pipeline", v12.CreatePipeline)          //创建流水线
		v1.POST("/pipeline/copy", v12.CopyPipeline)       //复制流水线
		v1.DELETE("/pipeline/:name", v12.DeletePipeline)
		v1.PUT("/pipeline/run", v12.StartPipeline)
		v1.PUT("/pipeline/stop", v12.StopPipeline)

		//历史流水线
		v1.GET("/hispipe", v12.ListHisPipe)

		//产品项目的增删改
		v1.GET("/project", v12.GetProject)
		v1.GET("/project/users/:id", v12.GetProjectUsers)
		v1.POST("/project", v12.CreateProject)
		v1.DELETE("/project/:id", v12.DeleteProject)
		v1.PUT("/project/user", v12.AddUserToProject)
		v1.DELETE("/project/user", v12.RemoveUserToProject)

		//节点管理
		v1.GET("/node", v12.GetAllNodes)
		v1.GET("/node/cpu_model", v12.GetNodeCpuModel)
		v1.GET("/node/kernal", v12.GetNodeKernalInfo)
		v1.POST("/node", v12.CreaeNode)

		//环境管理
		v1.GET("/env", v12.GetAllEnv)
		v1.GET("/env/info/:name", v12.QueryEnvInfo)
		v1.POST("/env", v12.CreateEnv)
		v1.PUT("/env", v12.UpdateEnv)
		v1.DELETE("/env/:name", v12.DeleteEnv)

		v1.GET("/log", v12.ListLog)

		v1.GET("/restful", v12.ListRestful)
		v1.POST("/restful", v12.CreateRestful)
		v1.POST("/restful/run", v12.RunApi)
		v1.PUT("/restful", v12.UpdateRestful)
		v1.DELETE("/restful/:name", v12.DeleteRestful)

		v1.GET("/restful/meau", v12.ListRestfulMeau)
		v1.POST("/restful/meau", v12.CreateRestfulMeau)
		v1.PUT("/restful/meau", v12.UpdateRestfulMeau)
		v1.DELETE("/restful/meau:name", v12.DeleteRestfulMeau)

		//工具菜单管理
		v1.GET("/tool/meau", v12.GetToolMeau)
		v1.POST("/tool/meau", v12.CreateToolMeau)
		v1.PUT("/tool/meau", v12.UpdateToolMeau)
		v1.DELETE("/tool/meau:name", v12.DeleteMeau)
		//工具管理
		v1.GET("/tool", v12.GetTool)
		v1.POST("/tool", v12.CreateTool)
		v1.PUT("/tool", v12.UpdateTool)
		v1.DELETE("/tool:name", v12.DeleteTool)

		v1.GET("/blog", v12.ArticleList)
		v1.POST("/blog", v12.CreateArticle)
		v1.PUT("/blog", v12.UpdateArticle)
		v1.DELETE("/blog:name", v12.DeleteArticle)

		v1.GET("/performance", v12.ListPerformance)
		v1.POST("/performance", v12.CreatePerformance)
		v1.PUT("/performance", v12.UpdatePerformance)
		v1.DELETE("/performance/:id", v12.DeletePerformance)

		v1.GET("/fio", v12.ListFio)
		v1.GET("/fio/export", v12.ExportExcelFio)
		v1.POST("/fio", v12.CreateFio)
		v1.PUT("/fio", v12.UpdateFio)
		v1.DELETE("/fio/:id", v12.DeleteFio)
	}

	super := R.Group("manager")
	super.Use(middleware.JWT())
	{
		super.GET("/policy", manager.GetPolicy)
		super.POST("/policy", manager.AddPolicy)
		super.DELETE("/policy/:id", manager.DeletePolicy)
		super.PUT("/policy/:id", manager.ModifyPolicy)

	}

	//R.StaticFS("/documents", gin.Dir("E:\\workspace\\gowork\\src\\palmer\\server\\documents", true))
	return R
}
